package com.itheima.sinagle;

public class Demo {
    public static void main(String[] args) {

        System.out.println("当前线程开始:"+Thread.currentThread().getName());

        System.out.println("开启一个新的线程:");
        //在main线程中 开启一个新的线程
        new Thread(new Runnable() {
            public void run() {
                //新的线程任务是 创建10对象
                for (int i = 0; i <10 ; i++) {
                    System.out.println("在"+Thread.currentThread().getName()+"获取对象"+Single.getInstance());
                }
            }
        }).start();
        //有个程序 保证某一个类型的对象在该程序 有且只有一个
        Single single1 = Single.getInstance();
        Single single2 = Single.getInstance();
        Single single3 = Single.getInstance();
        Single single4 = Single.getInstance();
        Single single5 = Single.getInstance();




        System.out.println(single1);
        System.out.println(single2);
        System.out.println(single3);
        System.out.println(single4);
        System.out.println(single5);

        System.out.println("当前线程结束:"+Thread.currentThread().getName());
    }
}
